#include<stdio.h>
#include<stdlib.h> // malloc, exit
#include<unistd.h> // fork
#include<signal.h>
#include<sys/wait.h>

// 信号处理函数
void sig_usr(int signo)
{
    int status = 0;
    switch (signo)
    {
    case SIGUSR1:
        printf("收到了 SIGUSR1 信号, 进程ID = %d \n", getpid() );
        break;
    case SIGCHLD:
        {
            printf("收到了 SIGCHLD 信号, 进程ID = %d \n", getpid() );
            pid_t pid = waitpid(-1, &status, WNOHANG);
            if (pid == 0)
            {
                return;
            }
            if (pid == -1)
            {
                return;
            }
            return;
        }
    
    default:
        break;
    }
}

int g_mygbltest = 0;

int main(int argc, char *const *argv)
{
    printf("程序开始执行 \n");

    ((fork() && fork()) || (fork() && fork()));
    for (; ; )
    {
        g_mygbltest++;
        sleep(1);
        printf("休息1s, 进程ID = %d \n", getpid());
    }
    
    printf("程序执行 \n");

    return 0;
}
